<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../include/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>字段管理页面</title>
<%@ include file="../include/easyui.jsp"%>
</head>
<body class="easyui-layout" style="font-family: '微软雅黑'">   
    <div data-options="region:'center',split:true,border:false,title:'字段列表'">
    	<div id="tb" style="padding:5px;height:auto">
		    <div>
				<form id="searchFrom">
					<input type="text" id="mti" name="mainTemplateId" class="easyui-validatebox" data-options="width:150,prompt: '主模板'"/>
					<span class="toolbar-item dialog-tool-separator"></span>
					<a href="javascript(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="query()">查询</a>
				</form>
				<shiro:hasPermission name="import:detailExcelTemplate:add">
					<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add();">添加</a>
					<span class="toolbar-item dialog-tool-separator"></span>
				</shiro:hasPermission>
				<shiro:hasPermission name="import:detailExcelTemplate:delete">
					<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" data-options="disabled:false"  onclick="del()">删除</a>
					<span class="toolbar-item dialog-tool-separator"></span>
				</shiro:hasPermission>
				<shiro:hasPermission name="import:detailExcelTemplate:update">
					<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="update()">修改</a>
					<span class="toolbar-item dialog-tool-separator"></span>
				</shiro:hasPermission>
		    </div>
		</div>
		<table id="dg"></table>
    </div>
	<div id="dlg"></div>
<script type="text/javascript">
var dg;	//字段datagrid
var dialog; //弹窗
$('#mti').combotree({
	width:150,
	method:'GET',
	url: '${ctx}/import/mainExcelTemplate/lists',
	idField : 'id',
	textFiled : 'name',
	iconCls: 'icon',
	animate:true
});

$(function(){
	dg=$('#dg').datagrid({
	method: "get",
    url:'${ctx}/import/detailExcelTemplate/list',
    fit : true,
	fitColumns : true,
	border : false,
	idField : 'id',
	pagination:true,
	rownumbers:true,
	pageNumber:1,
	pageSize : 10,
	pageList : [ 10, 20, 30, 40, 50 ],
	singleSelect:true,
	striped:true,
    columns:[[
        {field:'id',title:'id',hidden:true,sortable:true,width:100},
        {field:'mainTemplateId',title:'主模板',sortable:true,width:100,formatter : function(value, row, index) {
        	//var retVal = '${mainExcelTemplateMap[value]}';
			//return retVal;
			return value;
		}},
		{field:'fieldName',title:'字段名称',sortable:true,width:100},
		{field:'fieldType',title:'字段类型',sortable:true,width:100,formatter : function(value, row, index) {
			//TODO
			var retVal;
			if(value == '0'){
				retVal = '整形';
			}else if(value == '1'){
				retVal = '浮点型';
			}else if(value == '2'){
				retVal = '字符型';
			}else if(value == '3'){
				retVal = '布尔型';
			}
			return retVal;
		}},
        {field:'columnNum',title:'列数',sortable:true,width:100},
		{field:'sort',title:'排序',sortable:true,width:100},
		{field:'effective',title:'是否导入',sortable:true,width:100,formatter : function(value, row, index) {
			return value == 0 ?'导入':'不导入';
		}},
		{field:'nullable',title:'是否为空',sortable:true,width:100,formatter : function(value, row, index) {
			return value == 0 ?'可为空':'不为空';
		}}
    ]],
    enableHeaderClickMenu: false,
    enableHeaderContextMenu: false,
    enableRowContextMenu: false,
    toolbar:'#tb'
	});
});

//弹窗增加
function add() {
	$.ajaxSetup({type : 'GET'});
	dialog=$('#dlg').dialog({
	    title: '添加字段',
	    width: 400,
	    height: 260,
	    closed: false,
	    cache: false,
	    maximizable:true,
	    resizable:true,
	    href: '${ctx}/import/detailExcelTemplate/addForm',
	    modal: true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit();
			}
		},{
			text:'取消',
			handler:function(){
				dialog.panel('close');
			}
		}]
	});
}

//删除
function del(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"${ctx}/import/detailExcelTemplate/delete/"+row.id,
				success: function(data){
					successTip(data.message,dg);
				}
			});
		}
	});
}

//修改
function update(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) {
		return;
	}
	var rowIndex = row.id;
	$.ajaxSetup({type : 'GET'});
	dialog=$("#dlg").dialog({
	    title: '修改字段',
	    width: 400,
	    height: 260,
	    href: '${ctx}/import/detailExcelTemplate/updateForm/'+rowIndex,
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit();
			}
		},{
			text:'取消',
			handler:function(){
				dialog.panel('close');
			}
		}]
	});
}

//创建查询对象并查询
function query(){
	var obj=$("#searchFrom").serializeObject();
	dg.datagrid('load',obj);
}
</script>
</body>
</html>